<template>
  <div class="component-list" @dragstart="handleDragStart">
    <div v-for="(item, index) in componentList" :key="item.component" class="list" draggable="true" :data-index="index">
      <DataAnalysis v-if="item.icon === 'px-DataAnalysis'" class="px-icon-custom" />
      <span v-else-if="item.icon" class="iconfont" :class="'icon-' + item.icon" />
      <span v-else class="icon-text">{{ item.label }}</span>
    </div>
  </div>
</template>
<script setup lang="ts">
import componentList from "@visual/custom-component/component-list";
import { DataAnalysis } from "@px-ui/icons-vue";

function handleDragStart(e: DragEvent) {
  if (!(e.target instanceof HTMLElement)) return;

  // console.log("@@@DragStart: ", e.target.dataset.index);

  e.dataTransfer?.setData("index", e.target.dataset.index || "");
}
</script>
<style lang="scss" scoped>
::-webkit-scrollbar {
  width: 2px !important;
  height: 2px !important;
}

.component-list {
  position: relative;
  display: grid;
  grid-template-rows: repeat(auto-fill, 40px);
  grid-template-columns: repeat(auto-fill, 80px);
  grid-gap: 10px 19px;
  height: 65%;
  padding: 6px;
  opacity: 1;
  transition: opacity 0.5s 0.5s;

  .list {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 40px;
    padding: 2px 5px;
    color: #333;
    text-align: center;
    cursor: grab;
    border: 1px solid #ddd;

    &:active {
      cursor: grabbing;
    }

    .iconfont {
      font-size: 20px;
    }

    .icon-text {
      font-size: 14px;
      font-weight: 700;
    }

    .icon-wenben,
    .icon-biaoge {
      font-size: 18px;
    }

    .icon-tupian {
      font-size: 16px;
    }

    .px-icon-custom {
      width: 18px;
    }
  }
}
</style>
